class Writeboard < ActiveRecord::Base
  belongs_to :project
  belongs_to :user
  belongs_to :category
  has_many   :wikis,:order=>'id desc',:dependent=>:destroy
  after_create :log_save
  after_destroy :log_destroy
def icategory
  if self.category_id == 0 or self.category_id.nil?
  "uncategoried"
  else
  Category.find(self.category_id).name
  end
end
def log_save
  Log.info(self.project,
       "<a href=/projects/#{self.project_id}/writeboards/#{self.id}>#{self.name}</a>",
       4,
       "Posted by",
       self.user
    )
end

def log_destroy
  log = Log.find(:first,:conditions=>["project_id = ? and name = ? and type_id=? and label=? and user_id = ?",self.project.id,
       "<a href=/projects/#{self.project_id}/writeboards/#{self.id}>#{self.name}</a>",
       4,
       "Posted by",
       self.user.id])
       log.destroy unless log.nil?
end
end
